import api from '../../config/setting.js'
Page({
  data: {
    backFront: true,
    record: [
      {code: 100, msg: '匹配成功', name: '张三', score: 98},
      {code: 102, msg: '匹配人员不是我们社区人员，请注意。', name: '张三', score: 98}
    ]
  },
  switchCamera() {
    this.setData({
      backFront: !this.data.backFront
    })
  },
  takePhoto() {
    //1
    wx.showLoading({
      title: '检测中...',
      mask: true
    })
    //2. 拿到相机对象拍照
    const ctx = wx.createCameraContext()
    ctx.takePhoto({
      quality: 'high',
      success: (res) => {
        //3 res 返回已拍照的临时照片
        wx.uploadFile({
          url: api.face,
          filePath: res.tempImagePath,
          name: 'avatar',
          success: (response) => {
            console.log(response)
            let resdata = JSON.parse(response.data);
            console.log(resdata);
            if (resdata.code == 100 || resdata.code == 102) {
              console.log(resdata);
              resdata.avatar = res.tempImagePath;
              var oldRecord = this.data.record;
              oldRecord.unshift(resdata);
              console.log(oldRecord);
              this.setData({
                record: oldRecord
              });
            }
            else {
              wx.showToast({
                title: '请正常拍照',
              })
            }
          },
          complete: () => {
            wx.hideLoading()
          }
        })
      }
    });
  }
})